package com.lantosec.hmrp.modules.form.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.lantosec.hmrp.core.mvc.BaseEntity;
import com.lantosec.hmrp.modules.form.vo.FormColumnsVO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * <p>
 * 自定义表单列定义 实体类
 * </p>
 *
 * @author AutoCode
 * @since 2020-04-15
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("form_columns")
public class FormColumns extends BaseEntity<FormColumnsVO> {

    private static final long serialVersionUID = 1L;
    public FormColumns(FormColumnsVO vo){
        this.columnId = vo.getColumnId();
        this.tableId = vo.getTableId();
        this.columnName = vo.getColumnName();
        this.columnType = vo.getColumnType();
        this.ordinalPosition = vo.getOrdinalPosition();
        this.isNullable = vo.getIsNullable();
        this.dataType = vo.getDataType();
        this.characterMaximumLength = vo.getCharacterMaximumLength();
        this.numericPrecision = vo.getNumericPrecision();
        this.numericScale = vo.getNumericScale();
        this.datetimePrecision = vo.getDatetimePrecision();
        this.columnComment = vo.getColumnComment();
        this.primaryKey = vo.getPrimaryKey();
        this.foreignKey = vo.getForeignKey();
        this.primaryTableColumn = vo.getPrimaryTableColumn();
        this.valueType = vo.getValueType();
        this.valueData = vo.getValueData();
        this.createDate = vo.getCreateDate();
        this.createUserId = vo.getCreateUserId();
        this.createUserName = vo.getCreateUserName();
    }

    @Override
    public FormColumnsVO convertToVO(){
        return new FormColumnsVO(this);
    }


    /**
     * ID
     */
    @TableId(value = "column_id", type = IdType.ASSIGN_UUID)
    private String columnId;

    /**
     * 表ID
     */
    private String tableId;

    /**
     * 列名
     */
    private String columnName;

    /**
     * 列类型，BASE COLUMN基础表列，EXT COLUMN扩展列
     */
    private String columnType;

    /**
     * 排序
     */
    private Integer ordinalPosition;

    /**
     * 是否允许为空，NO否YES是
     */
    private String isNullable;

    /**
     * 数据类型
     */
    private String dataType;

    /**
     * 字符的最大长度
     */
    private Long characterMaximumLength;

    /**
     * 数值精度
     */
    private Long numericPrecision;

    /**
     * 数值刻度
     */
    private Long numericScale;

    /**
     * 日期刻度
     */
    private Long datetimePrecision;

    /**
     * 列描述
     */
    private String columnComment;

    /**
     * 是否主键
     */
    private Boolean primaryKey;

    /**
     * 是否外键
     */
    private Boolean foreignKey;

    /**
     * 对应主表的列
     */
    private String primaryTableColumn;

    /**
     * 值类型，DEFAULT默认值，SQL查询值，SQL LIST查询列表，DICTIONARIES字典，JAVASCRIPT MATH js公式，JAVA MATH java公式
     */
    private String valueType;

    /**
     * 值数据
     */
    private String valueData;

    /**
     * 创建时间
     */
    private Date createDate;

    /**
     * 创建用户ID
     */
    private String createUserId;

    /**
     * 创建用户名称
     */
    private String createUserName;


    public enum ColName {
        column_id, table_id, column_name, column_type, ordinal_position, is_nullable, data_type, character_maximum_length, numeric_precision, numeric_scale, datetime_precision, column_comment, primary_key, foreign_key, primary_table_column, value_type, value_data, create_date, create_user_id, create_user_name,
    }
}
